package com.yc.yyds.servlet;

import com.google.gson.Gson;
import com.yc.yyds.Bean.Result;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.Map;

@WebServlet(name = "GetUserMessageServlet", value = "/GetUserMessageServlet.s")
public class GetUserMessageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Map<String,Object> data = (Map<String, Object>) request.getSession().getAttribute("userMsg");
        if (data!=null){
            Result result = new Result(1,"获取用户信息成功",data);
            String json = new Gson().toJson(result);
            response.getWriter().append(json);
        }else {
            Result result = new Result(0,"用户信息获取失败",null);
            String json = new Gson().toJson(result);
            response.getWriter().append(json);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
